package Tk01;

public class MyThread implements Runnable{

    Thread attachThread;

    public void setAttachThread(Thread attachThread) {
        this.attachThread = attachThread;
    }

    public void run(){
        String name=Thread.currentThread().getName();
        if(name.equals("司机")){
            try{
                System.out.println("我是"+name+"在路上开车");
                System.out.println("想睡上三个小时再开车");
                Thread.sleep(1000*60*60);
            }catch (InterruptedException e){
                System.out.println(name+"你被唤醒了");
            }
            System.out.println(name+"继续开车");
        }else if(name.equals("警察")){
            for(int i=1;i<=3;i++){
                System.out.println(name+"喊，开车！");
            }
            try{
                Thread.sleep(500);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            attachThread.interrupt();
        }
    }
}
